package xyz.fefine;

import com.sun.org.apache.bcel.internal.classfile.Code;

import java.io.IOError;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
 * Created by feng_ on 2016/8/30.
 */
public class test {

    public static void regexTest(){

        Pattern p1 = Pattern.compile("([a-z]+)://([a-z|\\.]+).*");
        Pattern p2 = Pattern.compile("[\\w]+");
        //a(b(c))d   //group1:abcd  g2:bc g3:c
        Pattern p3 = Pattern.compile("([a-z]+)((:?)(//))");


        String url = "http://fefine.xyz";

        Matcher m1 = p1.matcher(url);
        Matcher m2 = p2.matcher(url);
        Matcher m3 = p3.matcher(url);

        while (m1.find()){
            System.out.println(m1.group());
        }

        while (m2.find()){
            System.out.println("m2:"+m2.group());
        }

        int i = 0;
        while (m2.find(i)){ //从i开始的位置搜索字符串
            System.out.println("m22:" + m2.group());
            i ++;
        }

        while (m3.find()) {
                            //这里的count是<=
            for (int j = 0; j <= m3.groupCount(); j++) {
                System.out.print("["+m3.group(j)+"] ");
            }
            System.out.println();
        }

//        System.out.println(m1.group(0));
//        System.out.println(m1.group(1));
    }

    public static void stringTest(){

        String s = "http://fefine.xyz";
        //从s[0]-s[4]
        System.out.println(s.substring(1,5));

    }

    public static void regexTest2(String line2) {
        String pattern = "\\s*((//.*)|([0-9]+)|(\"(\\\\\"|\\\\\\\\|\\\\n|[^\"])*\")|[A-Z_a-z][A-Z_a-z0-9]*|==|<=|>=|&&|\\|\\||\\p{Punct})?";

        Matcher m2 = Pattern.compile(pattern).matcher(line2);
        m2.useTransparentBounds(true).useAnchoringBounds(false);
        int start = 0;
        int end = line2.length();
        while (start < end) {
            System.out.println(start);
            m2.region(start,end);
            if (m2.lookingAt()) {
                for (int i = 0; i <= m2.groupCount(); i++) {
                    System.out.print(i+"["+m2.group(i)+"] ");
                }
                System.out.println();
            }
            start = m2.end();   //循環
        }

        System.out.println("----------------------------------");


    }

    public static void main(String[] args) throws IOException{

        /**
         *
         * find([i])    从任意位置开始匹配
         * lookingAt()  只要输入的第一部分匹配就成功
         * matchers()   只有全部匹配才会成功
         *
         *
         */

//        regexTest2("while a==10 {");
//        regexTest2("print ((currentTime() - t) + \"ms\")");
//        regexTest2("\"nihao\"");
//        regexTest2("== {");
//        //                空格  2注释 3整形字面量  4字符串字面量                          5标识符                 5比较,逻辑运算      \p{Punct} \p{Punct}	Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
//        String pattern = "\\s*((//.*)|([0-9]+)|(\"(\\\\\"|\\\\\\\\|\\\\n|[^\"])*\")|[A-Z_a-z][A-Z_a-z0-9]*|==|<=|>=|&&|\\|\\||\\p{Punct})?";
//                                              " \"       \\      \n       任意字符
//        \p{Punct}	Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~


/*        LineNumberReader reader = new LineNumberReader(new CodeDialog());
        //String s;
        Stream<String> lines = reader.lines();
        lines.forEach((s) -> System.out.println(s));*/

/*        List<Object> list = new ArrayList<>();
        list.add(null);
        System.out.println(list.size());*/
        //内部都有计数器对添加的元素进行计数
/*        Map<Object, Object> map = new HashMap<>();
        map.put(null, null);
        System.out.println(map.size());*/
/*        String s = "\\n";
        System.out.println("def".matches("[\\n|;|}|)|(def)]*"));
        System.out.println(s.matches("\\\\n|;|}|\\)|def"));*/

        //   \n   \\n

        List as = new ArrayList<Integer>();
        as.add(1);
        as.add(12);
        as.add(13);
        as.add(14);
        as.add(15);

        Integer[] ins;

//        System.arraycopy(as, 0, ins, 0, 5);
        ins = (Integer[])as.toArray(new Integer[0]);


        for (int i : ins) {
            System.out.println(i);
        }
    }

}
